/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * This is a test case about the use of "!!" two-way sync binding in the component 'SideBarContainer'.
 */
exports.source = `
@Entry
@ComponentV2
struct SideBarContainerExample {
  @Local arr: number[] = [1, 2, 3]
  @Local current: number = 1
  @Local showSideBar: boolean = true
  @Local isOn1: boolean = true
  @Local isOn2: boolean = true

  build() {
    SideBarContainer(SideBarContainerType.Embed) {
      Column() {
        ForEach(this.arr, (item: number) => {
          Column({ space: 5 }) {
            Text("Index0" + item)
              .fontColor(this.current === item ? '#0A59F7' : '#999')
          }
          .onClick(() => {
            this.current = item
          })
        }, (item: string) => item)
      }

      Column() {
        Text('SideBarContainer content text1').fontSize(25)
        Text('SideBarContainer content text2').fontSize(25)
        Toggle({ type: ToggleType.Switch, isOn: this.isOn1!! })
        Toggle({ type: ToggleType.Switch, isOn: this.isOn2 })
      }
    }
    .showSideBar(this.showSideBar!!)
  }
}
`

exports.expectResult =
`"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
if (!("finalizeConstruction" in ViewPU.prototype)) {
    Reflect.set(ViewPU.prototype, "finalizeConstruction", () => { });
}
class SideBarContainerExample extends ViewV2 {
    constructor(parent, params, __localStorage, elmtId = -1, paramsLambda, extraInfo) {
        super(parent, elmtId, extraInfo);
        this.arr = [1, 2, 3];
        this.current = 1;
        this.showSideBar = true;
        this.isOn1 = true;
        this.isOn2 = true;
        this.finalizeConstruction();
    }
    initialRender() {
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            SideBarContainer.create(SideBarContainerType.Embed);
            SideBarContainer.showSideBar({ value: this.showSideBar, $value: newValue => { this.showSideBar = newValue; } });
        }, SideBarContainer);
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            Column.create();
        }, Column);
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            ForEach.create();
            const forEachItemGenFunction = _item => {
                const item = _item;
                this.observeComponentCreation2((elmtId, isInitialRender) => {
                    Column.create({ space: 5 });
                    Column.onClick(() => {
                        this.current = item;
                    });
                }, Column);
                this.observeComponentCreation2((elmtId, isInitialRender) => {
                    Text.create("Index0" + item);
                    Text.fontColor(this.current === item ? '#0A59F7' : '#999');
                }, Text);
                Text.pop();
                Column.pop();
            };
            this.forEachUpdateFunction(elmtId, this.arr, forEachItemGenFunction, (item) => item, false, false);
        }, ForEach);
        ForEach.pop();
        Column.pop();
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            Column.create();
        }, Column);
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            Text.create('SideBarContainer content text1');
            Text.fontSize(25);
        }, Text);
        Text.pop();
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            Text.create('SideBarContainer content text2');
            Text.fontSize(25);
        }, Text);
        Text.pop();
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            Toggle.create({ type: ToggleType.Switch, isOn: this.isOn1, $isOn: newValue => { this.isOn1 = newValue; } });
        }, Toggle);
        Toggle.pop();
        this.observeComponentCreation2((elmtId, isInitialRender) => {
            Toggle.create({ type: ToggleType.Switch, isOn: this.isOn2 });
        }, Toggle);
        Toggle.pop();
        Column.pop();
        SideBarContainer.pop();
    }
    rerender() {
        this.updateDirtyElements();
    }
    static getEntryName() {
        return "SideBarContainerExample";
    }
}
__decorate([
    Local
], SideBarContainerExample.prototype, "arr", void 0);
__decorate([
    Local
], SideBarContainerExample.prototype, "current", void 0);
__decorate([
    Local
], SideBarContainerExample.prototype, "showSideBar", void 0);
__decorate([
    Local
], SideBarContainerExample.prototype, "isOn1", void 0);
__decorate([
    Local
], SideBarContainerExample.prototype, "isOn2", void 0);
ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent());
loadDocument(new SideBarContainerExample(undefined, {}));
ViewStackProcessor.StopGetAccessRecording();
`
